var __spreadArray =
  (this && this.__spreadArray) ||
  function (to, from, pack) {
    if (pack || arguments.length === 2)
      for (var i = 0, l = from.length, ar; i < l; i++) {
        if (ar || !(i in from)) {
          if (!ar) ar = Array.prototype.slice.call(from, 0, i);
          ar[i] = from[i];
        }
      }
    return to.concat(ar || Array.prototype.slice.call(from));
  };
import React, { useRef, useState } from 'react';
import { Input, InputNumber, Slider, Space, Switch } from 'antd';
import { LinkSet } from './LinkSet';
import { ConfigWordsLimit } from './ConfigWordsLimit';
import { JsonInput } from './JsonInput';
import { useConfigContext } from '../../contexts/ConfigContext';
export function ConfigProp(props) {
  var propOwner = props.propOwner,
    namepath = props.namepath,
    propName = props.propName,
    propDefaultValue = props.propDefaultValue;
  var forceRender = useConfigContext().forceRender;
  var typeofPropDefaultValue = useRef(typeof propDefaultValue);
  var _a = useState(propDefaultValue),
    propCurrentValue = _a[0],
    setPropCurrentValue = _a[1];
  var handleChangePropValue = function (newValue) {
    propOwner[propName] = newValue;
    setPropCurrentValue(newValue);
    forceRender();
  };
  var marks = {
    8: '8',
    12: '12',
    16: '16'
  };
  switch (propName) {
    case 'layout':
      return React.createElement(
        Space,
        null,
        React.createElement('strong', null, 'layout\uFF1A'),
        React.createElement(Slider, {
          value: propCurrentValue,
          marks: marks,
          min: 1,
          max: 24,
          onChange: handleChangePropValue,
          style: { width: 140 }
        }),
        React.createElement(LinkSet, { targetType: 'number', namepath: namepath })
      );
    case 'name':
      return React.createElement(JsonInput, { propOwner: propOwner, propName: 'name' });
    case 'initialValue':
      return React.createElement(JsonInput, { propOwner: propOwner, propName: 'initialValue' });
    case 'wordsLimit':
      return React.createElement(ConfigWordsLimit, { extra: propOwner });
  }
  switch (typeofPropDefaultValue.current) {
    case 'object':
      var propOwner_1 = propDefaultValue;
      var propOwnerEntries = Object.entries(propOwner_1);
      return React.createElement(
        'div',
        null,
        React.createElement('strong', null, propName, '\uFF1A'),
        React.createElement(
          'div',
          { className: 'configs-area' },
          propOwnerEntries.map(function (_a) {
            var pName = _a[0],
              value = _a[1];
            return React.createElement(ConfigProp, {
              key: pName,
              propOwner: propOwner_1,
              namepath: __spreadArray(__spreadArray([], namepath, true), [pName], false),
              propName: pName,
              propDefaultValue: value
            });
          })
        )
      );
    case 'boolean':
      return React.createElement(
        Space,
        null,
        React.createElement('strong', null, propName, '\uFF1A'),
        React.createElement(Switch, { checked: propCurrentValue, onChange: handleChangePropValue }),
        React.createElement(LinkSet, { targetType: 'boolean', namepath: namepath })
      );
    case 'string':
      return React.createElement(
        Space,
        null,
        React.createElement('strong', null, propName, '\uFF1A'),
        React.createElement(Input, {
          prefix: '"',
          suffix: '"',
          value: propCurrentValue,
          onChange: function (e) {
            return handleChangePropValue(e.target.value);
          }
        }),
        React.createElement(LinkSet, { targetType: 'string', namepath: namepath })
      );
    case 'number':
      return React.createElement(
        Space,
        null,
        React.createElement('strong', null, propName, '\uFF1A'),
        React.createElement(InputNumber, {
          value: propCurrentValue,
          onChange: handleChangePropValue,
          bordered: false
        }),
        React.createElement(LinkSet, { targetType: 'number', namepath: namepath })
      );
    default:
      return null;
  }
}
